package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.TravelOrderRefund;
import com.ktgj.customer.service.ITravelOrderRefundService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-08-03
 */
@RestController
@RequestMapping("/orderRefund")
public class TravelOrderRefundController extends BaseController
{
    @Autowired
    private ITravelOrderRefundService travelOrderRefundService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize(hasPermi = "system:refund:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TravelOrderRefund travelOrderRefund)
    {
        startPage();
        List<TravelOrderRefund> list = travelOrderRefundService.selectTravelOrderRefundList(travelOrderRefund);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "system:refund:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelOrderRefund travelOrderRefund) throws IOException
    {
        List<TravelOrderRefund> list = travelOrderRefundService.selectTravelOrderRefundList(travelOrderRefund);
        ExcelUtil<TravelOrderRefund> util = new ExcelUtil<TravelOrderRefund>(TravelOrderRefund.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize(hasPermi = "system:refund:query")
    @PostMapping("/getOrderRefund")
    public AjaxResult getOrderRefund(@RequestBody Map<String, Long> map)
    {
        Long orderRefundId = map.get("orderRefundId");
        if (orderRefundId != null)
        {
            return AjaxResult.success(travelOrderRefundService.selectTravelOrderRefundById(orderRefundId));
        }
        return AjaxResult.error("参数错误！");
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "system:refund:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelOrderRefund travelOrderRefund)
    {
        return toAjax(travelOrderRefundService.insertTravelOrderRefund(travelOrderRefund));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize(hasPermi = "system:refund:edit")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editOrderRefund")
    public AjaxResult editOrderRefund(@RequestBody TravelOrderRefund travelOrderRefund)
    {
        int rows = travelOrderRefundService.updateTravelOrderRefund(travelOrderRefund);
        if (rows > 0)
        {
            return AjaxResult.success("审核退单成功！");
        }
        return AjaxResult.error("审核退单失败！");
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "system:refund:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderrefundids}")
    public AjaxResult remove(@PathVariable Long[] orderrefundids)
    {
        return toAjax(travelOrderRefundService.deleteTravelOrderRefundByIds(orderrefundids));
    }
}
